﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_RKCDT : System.Web.UI.Page
{
    private string num = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        btnOK.Attributes.Add("onclick", "javascript:if(confirm('" + "确认无误，并提交么？" + "')== false) return false;");
    }
    protected void btnPGCX_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("PGCX.aspx?Pinzhong={0}", "酸洗热轧"));
        txtPinzhong.Text = Request.QueryString["Pinzhong"];
        txtPinzhong.Attributes["contentEditable"] = "false";
        txtGuige.Text = Request.QueryString["Guige"];
        txtGuige.Attributes["contentEditable"] = "false";
        num = Request.QueryString["Num"];
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        int checkValue = 0;
        RkcdtInfo rs = new RkcdtInfo();
        rs.Num = num;
        rs.Banzu = Session["用户信息.班组"].ToString();
        rs.Tianbao = Session["用户信息.姓名"].ToString();
        rs.Kday = DateTime.Now.ToString();
        string dh = "";
        switch (Session["用户信息.部门"].ToString())
        {
            case "不锈钢热轧库":
                dh = "BX"; break;
            case "碳钢热轧库":
                dh = "TG"; break;
            case "酸洗库":
                dh = "SX"; break;
            default:
                break;
        }
        rs.Dtnum = dh + rs.Kday;
        checkValue = BLLFactory.CreateRkcdtBLL().Add(rs);
        if (checkValue >= 1)
        {
            Response.Write(" <script   language=javascript> window.alert( ' 提交成功！ ');</script> ");
        }
        if (txtKN.Text.ToString() != "")
        {
            decimal kn = Convert.ToDecimal(txtKN.Text.ToString());
            decimal knwj = Convert.ToDecimal(txtKNWJ.Text.ToString());
            decimal knkl = Convert.ToDecimal(txtKNKL.Text.ToString());
            if (kn < (knwj + knkl))
                Response.Write(" <script   language=javascript> window.alert( ' 库内、库内未缴库、库内可利用数量不正确！ ');</script> ");
            else
            {
                BLLFactory.CreateRkcdtBLL().UpdateKN(rs.Dtnum, kn);
                BLLFactory.CreateRkcdtBLL().UpdateKNWJ(rs.Dtnum, knwj);
                BLLFactory.CreateRkcdtBLL().UpdateKNKL(rs.Dtnum, knkl);
            }
        }
        if (txtDK.Text.ToString() != "")
        {
            decimal dk = Convert.ToDecimal(txtDK.Text.ToString());
            decimal dkwj = Convert.ToDecimal(txtDKWJ.Text.ToString());
            decimal dkkl = Convert.ToDecimal(txtDKKL.Text.ToString());
            if (dk < (dkwj + dkkl))
                Response.Write(" <script   language=javascript> window.alert( ' 东库、东库未缴库、东库可利用数量不正确！ ');</script> ");
            else
            {
                BLLFactory.CreateRkcdtBLL().UpdateDK(rs.Dtnum, dk);
                BLLFactory.CreateRkcdtBLL().UpdateDKWJ(rs.Dtnum, dkwj);
                BLLFactory.CreateRkcdtBLL().UpdateDKKL(rs.Dtnum, dkkl);
            }
        }
        Response.Redirect("RKCDTJL.aspx");
    }
    protected void btnRepeat_Click(object sender, EventArgs e)
    {
        txtKN.Text = "";
        txtKNWJ.Text = "";
        txtKNKL.Text = "";
        txtDK.Text = "";
        txtDKWJ.Text = "";
        txtDKKL.Text = "";
    }
}
